package com.molyfun.parents.activity.record.itemview;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.molyfun.parents.R;
import com.molyfun.parents.rest.bean.RecordResponse;
import com.molyfun.parents.utils.TimeUtils;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by william(liuchao.hit@gmail.com).
 * Date:11/3/16.
 *
 * 此类为容器
 */
public class RecordItemView extends LinearLayout{

    protected LayoutInflater layoutInflater;

    private Context context;

    @InjectView(R.id.record_date)
    TextView mRecordDate;
    @InjectView(R.id.record_time)
    TextView mRecordTime;
    @InjectView(R.id.cell_container)
    LinearLayout mCellContainer;
    @InjectView(R.id.icon_type)
    ImageView mIconType;
    @InjectView(R.id.date_layout)
    LinearLayout mDateLayout;


    public RecordItemView(Context context, AttributeSet attrs, int defStyle) {
        this(context, attrs);
    }

    public RecordItemView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context, attrs);
    }

    public RecordItemView(Context context) {
        super(context);
        init(context, null);
    }

    private void init(Context context, AttributeSet attrs) {
        this.context = context;
        layoutInflater = LayoutInflater.from(context);
        layoutInflater.inflate(R.layout.widget_record_item, this);
        ButterKnife.inject(this);
    }

    /**
     * init view
     *
     */
    public void initData(RecordResponse.RecordBean recordBean, boolean showDate, BaseRecordView.RecordOperationCallBack recordOperationCallBack) {
        mCellContainer.removeAllViews();
        BaseRecordView recordView = RecordViewFactory.getView(context, recordBean);
        recordView.setRecordOperationCallBack(recordOperationCallBack);
        mCellContainer.addView(recordView);
        if(showDate){
            mDateLayout.setVisibility(View.VISIBLE);
            mRecordDate.setText(TimeUtils.transForDate(recordBean.getCreatedatetime()));
        }else{
            mDateLayout.setVisibility(View.GONE);
        }
        mRecordTime.setText(TimeUtils.transForTime(recordBean.getCreatedatetime()));

        switch (recordBean.getType()){

            case RecordViewFactory.RecordType.RecordTypeText:
                mIconType.setImageResource(R.mipmap.ic_record_text);
                break;

            case RecordViewFactory.RecordType.RecordTypeVoice:
                mIconType.setImageResource(R.mipmap.ic_record_history_voice);
                break;
            case RecordViewFactory.RecordType.RecordTypeImage:
                mIconType.setImageResource(R.mipmap.ic_record_photo);
                break;
            case RecordViewFactory.RecordType.RecordTypeFile:
            case RecordViewFactory.RecordType.RecordTypeVideo:
            default:
                mIconType.setImageResource(R.mipmap.ic_record_video);
                break;


        }
    }

}